****************************************
* Evaluation of the pan-European ballot*
****************************************

// use [Your local path to the dataset "pan_european_district_data.dta"], clear

* 1. Creation of variables
***************************

* Weights

tab natvote_closed if UserCtry=="fr"

gen weight=.
replace weight=(249*421)/(1000*8) if natvote_closed==1 & UserCtry=="fr"
replace weight=(208*421)/(1000*14) if natvote_closed==2 & UserCtry=="fr"
replace weight=(140*421)/(1000*82) if natvote_closed==3 & UserCtry=="fr"
replace weight=(99*421)/(1000*49) if natvote_closed==4 & UserCtry=="fr"
replace weight=(90*421)/(1000*93) if natvote_closed==5 & UserCtry=="fr"
replace weight=(66*421)/(1000*63) if natvote_closed==6 & UserCtry=="fr"
replace weight=(148*421)/(1000*112) if natvote_closed==99 & UserCtry=="fr"

tab natvote_closed if UserCtry=="de"

replace weight=(366*316)/(1000*28) if natvote_closed==1 & UserCtry=="de"
replace weight=(282*316)/(1000*99) if natvote_closed==2 & UserCtry=="de"
replace weight=(111*316)/(1000*96) if natvote_closed==3 & UserCtry=="de"
replace weight=(77*316)/(1000*14) if natvote_closed==4 & UserCtry=="de"
replace weight=(73*316)/(1000*31) if natvote_closed==5 & UserCtry=="de"
replace weight=(35*316)/(1000*2) if natvote_closed==6 & UserCtry=="de"
replace weight=(14*316)/(1000*3) if natvote_closed==8 & UserCtry=="de"
replace weight=(10*316)/(1000*16) if natvote_closed==10 & UserCtry=="de"
replace weight=(7*316)/(1000*4) if natvote_closed==11 & UserCtry=="de"
replace weight=(6*316)/(1000*1) if natvote_closed==13 & UserCtry=="de"
replace weight=(18*316)/(1000*22) if natvote_closed==99 & UserCtry=="de"

tab natvote_open if UserCtry=="se"

replace weight=(244*379)/(1000*55) if natvote_open==1 & UserCtry=="se"
replace weight=(153*379)/(1000*32) if natvote_open==2 & UserCtry=="se"
replace weight=(136*379)/(1000*13) if natvote_open==3 & UserCtry=="se"
replace weight=(10*379)/(1000*59) if natvote_open==4 & UserCtry=="se"
replace weight=(97*379)/(1000*14) if natvote_open==5 & UserCtry=="se"
replace weight=(65*379)/(1000*50) if natvote_open==6 & UserCtry=="se"
replace weight=(63*379)/(1000*50) if natvote_open==7 & UserCtry=="se"
replace weight=(60*379)/(1000*25) if natvote_open==8 & UserCtry=="se"
replace weight=(53*379)/(1000*49) if natvote_open==9 & UserCtry=="se"
replace weight=(29*379)/(1000*32) if natvote_open==99 & UserCtry=="se"

* Number of co-nationals on each list

gen number_nationals_list1=number_fr_list1 if UserCtry=="fr"
gen number_nationals_list2=number_fr_list2 if UserCtry=="fr"
gen number_nationals_list3=number_fr_list3 if UserCtry=="fr"
gen number_nationals_list4=number_fr_list4 if UserCtry=="fr"
gen number_nationals_list5=number_fr_list5 if UserCtry=="fr"
gen number_nationals_list6=number_fr_list6 if UserCtry=="fr"
gen number_nationals_list7=number_fr_list7 if UserCtry=="fr"

replace number_nationals_list1=number_ger_list1 if UserCtry=="de"
replace number_nationals_list2=number_ger_list2 if UserCtry=="de"
replace number_nationals_list3=number_ger_list3 if UserCtry=="de"
replace number_nationals_list4=number_ger_list4 if UserCtry=="de"
replace number_nationals_list5=number_ger_list5 if UserCtry=="de"
replace number_nationals_list6=number_ger_list6 if UserCtry=="de"
replace number_nationals_list7=number_ger_list7 if UserCtry=="de"

replace number_nationals_list1=number_swe_list1 if UserCtry=="se"
replace number_nationals_list2=number_swe_list2 if UserCtry=="se"
replace number_nationals_list3=number_swe_list3 if UserCtry=="se"
replace number_nationals_list4=number_swe_list4 if UserCtry=="se"
replace number_nationals_list5=number_swe_list5 if UserCtry=="se"
replace number_nationals_list6=number_swe_list6 if UserCtry=="se"
replace number_nationals_list7=number_swe_list7 if UserCtry=="se"

* Number of co-nationals on each list (among nine first candidates)

gen number_nationals_list1_nine=number_fr_list1_nine if UserCtry=="fr"
gen number_nationals_list2_nine=number_fr_list2_nine if UserCtry=="fr"
gen number_nationals_list3_nine=number_fr_list3_nine if UserCtry=="fr"
gen number_nationals_list4_nine=number_fr_list4_nine if UserCtry=="fr"
gen number_nationals_list5_nine=number_fr_list5_nine if UserCtry=="fr"
gen number_nationals_list6_nine=number_fr_list6_nine if UserCtry=="fr"
gen number_nationals_list7_nine=number_fr_list7_nine if UserCtry=="fr"

replace number_nationals_list1_nine=number_ger_list1_nine if UserCtry=="de"
replace number_nationals_list2_nine=number_ger_list2_nine if UserCtry=="de"
replace number_nationals_list3_nine=number_ger_list3_nine if UserCtry=="de"
replace number_nationals_list4_nine=number_ger_list4_nine if UserCtry=="de"
replace number_nationals_list5_nine=number_ger_list5_nine if UserCtry=="de"
replace number_nationals_list6_nine=number_ger_list6_nine if UserCtry=="de"
replace number_nationals_list7_nine=number_ger_list7_nine if UserCtry=="de"

replace number_nationals_list1_nine=number_swe_list1_nine if UserCtry=="se"
replace number_nationals_list2_nine=number_swe_list2_nine if UserCtry=="se"
replace number_nationals_list3_nine=number_swe_list3_nine if UserCtry=="se"
replace number_nationals_list4_nine=number_swe_list4_nine if UserCtry=="se"
replace number_nationals_list5_nine=number_swe_list5_nine if UserCtry=="se"
replace number_nationals_list6_nine=number_swe_list6_nine if UserCtry=="se"
replace number_nationals_list7_nine=number_swe_list7_nine if UserCtry=="se"

* Number of co-nationals on each list (among eight first candidates)

gen number_nationals_list1_eight=number_fr_list1_eight if UserCtry=="fr"
gen number_nationals_list2_eight=number_fr_list2_eight if UserCtry=="fr"
gen number_nationals_list3_eight=number_fr_list3_eight if UserCtry=="fr"
gen number_nationals_list4_eight=number_fr_list4_eight if UserCtry=="fr"
gen number_nationals_list5_eight=number_fr_list5_eight if UserCtry=="fr"
gen number_nationals_list6_eight=number_fr_list6_eight if UserCtry=="fr"
gen number_nationals_list7_eight=number_fr_list7_eight if UserCtry=="fr"

replace number_nationals_list1_eight=number_ger_list1_eight if UserCtry=="de"
replace number_nationals_list2_eight=number_ger_list2_eight if UserCtry=="de"
replace number_nationals_list3_eight=number_ger_list3_eight if UserCtry=="de"
replace number_nationals_list4_eight=number_ger_list4_eight if UserCtry=="de"
replace number_nationals_list5_eight=number_ger_list5_eight if UserCtry=="de"
replace number_nationals_list6_eight=number_ger_list6_eight if UserCtry=="de"
replace number_nationals_list7_eight=number_ger_list7_eight if UserCtry=="de"

replace number_nationals_list1_eight=number_swe_list1_eight if UserCtry=="se"
replace number_nationals_list2_eight=number_swe_list2_eight if UserCtry=="se"
replace number_nationals_list3_eight=number_swe_list3_eight if UserCtry=="se"
replace number_nationals_list4_eight=number_swe_list4_eight if UserCtry=="se"
replace number_nationals_list5_eight=number_swe_list5_eight if UserCtry=="se"
replace number_nationals_list6_eight=number_swe_list6_eight if UserCtry=="se"
replace number_nationals_list7_eight=number_swe_list7_eight if UserCtry=="se"

* Number of co-nationals on each list (among seven first candidates)

gen number_nationals_list1_seven=number_fr_list1_seven if UserCtry=="fr"
gen number_nationals_list2_seven=number_fr_list2_seven if UserCtry=="fr"
gen number_nationals_list3_seven=number_fr_list3_seven if UserCtry=="fr"
gen number_nationals_list4_seven=number_fr_list4_seven if UserCtry=="fr"
gen number_nationals_list5_seven=number_fr_list5_seven if UserCtry=="fr"
gen number_nationals_list6_seven=number_fr_list6_seven if UserCtry=="fr"
gen number_nationals_list7_seven=number_fr_list7_seven if UserCtry=="fr"

replace number_nationals_list1_seven=number_ger_list1_seven if UserCtry=="de"
replace number_nationals_list2_seven=number_ger_list2_seven if UserCtry=="de"
replace number_nationals_list3_seven=number_ger_list3_seven if UserCtry=="de"
replace number_nationals_list4_seven=number_ger_list4_seven if UserCtry=="de"
replace number_nationals_list5_seven=number_ger_list5_seven if UserCtry=="de"
replace number_nationals_list6_seven=number_ger_list6_seven if UserCtry=="de"
replace number_nationals_list7_seven=number_ger_list7_seven if UserCtry=="de"

replace number_nationals_list1_seven=number_swe_list1_seven if UserCtry=="se"
replace number_nationals_list2_seven=number_swe_list2_seven if UserCtry=="se"
replace number_nationals_list3_seven=number_swe_list3_seven if UserCtry=="se"
replace number_nationals_list4_seven=number_swe_list4_seven if UserCtry=="se"
replace number_nationals_list5_seven=number_swe_list5_seven if UserCtry=="se"
replace number_nationals_list6_seven=number_swe_list6_seven if UserCtry=="se"
replace number_nationals_list7_seven=number_swe_list7_seven if UserCtry=="se"

* Number of co-nationals on each list (among six first candidates)

gen number_nationals_list1_six=number_fr_list1_six if UserCtry=="fr"
gen number_nationals_list2_six=number_fr_list2_six if UserCtry=="fr"
gen number_nationals_list3_six=number_fr_list3_six if UserCtry=="fr"
gen number_nationals_list4_six=number_fr_list4_six if UserCtry=="fr"
gen number_nationals_list5_six=number_fr_list5_six if UserCtry=="fr"
gen number_nationals_list6_six=number_fr_list6_six if UserCtry=="fr"
gen number_nationals_list7_six=number_fr_list7_six if UserCtry=="fr"

replace number_nationals_list1_six=number_ger_list1_six if UserCtry=="de"
replace number_nationals_list2_six=number_ger_list2_six if UserCtry=="de"
replace number_nationals_list3_six=number_ger_list3_six if UserCtry=="de"
replace number_nationals_list4_six=number_ger_list4_six if UserCtry=="de"
replace number_nationals_list5_six=number_ger_list5_six if UserCtry=="de"
replace number_nationals_list6_six=number_ger_list6_six if UserCtry=="de"
replace number_nationals_list7_six=number_ger_list7_six if UserCtry=="de"

replace number_nationals_list1_six=number_swe_list1_six if UserCtry=="se"
replace number_nationals_list2_six=number_swe_list2_six if UserCtry=="se"
replace number_nationals_list3_six=number_swe_list3_six if UserCtry=="se"
replace number_nationals_list4_six=number_swe_list4_six if UserCtry=="se"
replace number_nationals_list5_six=number_swe_list5_six if UserCtry=="se"
replace number_nationals_list6_six=number_swe_list6_six if UserCtry=="se"
replace number_nationals_list7_six=number_swe_list7_six if UserCtry=="se"

* Number of co-nationals on each list (among five first candidates)

gen number_nationals_list1_five=number_fr_list1_five if UserCtry=="fr"
gen number_nationals_list2_five=number_fr_list2_five if UserCtry=="fr"
gen number_nationals_list3_five=number_fr_list3_five if UserCtry=="fr"
gen number_nationals_list4_five=number_fr_list4_five if UserCtry=="fr"
gen number_nationals_list5_five=number_fr_list5_five if UserCtry=="fr"
gen number_nationals_list6_five=number_fr_list6_five if UserCtry=="fr"
gen number_nationals_list7_five=number_fr_list7_five if UserCtry=="fr"

replace number_nationals_list1_five=number_ger_list1_five if UserCtry=="de"
replace number_nationals_list2_five=number_ger_list2_five if UserCtry=="de"
replace number_nationals_list3_five=number_ger_list3_five if UserCtry=="de"
replace number_nationals_list4_five=number_ger_list4_five if UserCtry=="de"
replace number_nationals_list5_five=number_ger_list5_five if UserCtry=="de"
replace number_nationals_list6_five=number_ger_list6_five if UserCtry=="de"
replace number_nationals_list7_five=number_ger_list7_five if UserCtry=="de"

replace number_nationals_list1_five=number_swe_list1_five if UserCtry=="se"
replace number_nationals_list2_five=number_swe_list2_five if UserCtry=="se"
replace number_nationals_list3_five=number_swe_list3_five if UserCtry=="se"
replace number_nationals_list4_five=number_swe_list4_five if UserCtry=="se"
replace number_nationals_list5_five=number_swe_list5_five if UserCtry=="se"
replace number_nationals_list6_five=number_swe_list6_five if UserCtry=="se"
replace number_nationals_list7_five=number_swe_list7_five if UserCtry=="se"

* Number of co-nationals on each list (among four first candidates)

gen number_nationals_list1_four=number_fr_list1_four if UserCtry=="fr"
gen number_nationals_list2_four=number_fr_list2_four if UserCtry=="fr"
gen number_nationals_list3_four=number_fr_list3_four if UserCtry=="fr"
gen number_nationals_list4_four=number_fr_list4_four if UserCtry=="fr"
gen number_nationals_list5_four=number_fr_list5_four if UserCtry=="fr"
gen number_nationals_list6_four=number_fr_list6_four if UserCtry=="fr"
gen number_nationals_list7_four=number_fr_list7_four if UserCtry=="fr"

replace number_nationals_list1_four=number_ger_list1_four if UserCtry=="de"
replace number_nationals_list2_four=number_ger_list2_four if UserCtry=="de"
replace number_nationals_list3_four=number_ger_list3_four if UserCtry=="de"
replace number_nationals_list4_four=number_ger_list4_four if UserCtry=="de"
replace number_nationals_list5_four=number_ger_list5_four if UserCtry=="de"
replace number_nationals_list6_four=number_ger_list6_four if UserCtry=="de"
replace number_nationals_list7_four=number_ger_list7_four if UserCtry=="de"

replace number_nationals_list1_four=number_swe_list1_four if UserCtry=="se"
replace number_nationals_list2_four=number_swe_list2_four if UserCtry=="se"
replace number_nationals_list3_four=number_swe_list3_four if UserCtry=="se"
replace number_nationals_list4_four=number_swe_list4_four if UserCtry=="se"
replace number_nationals_list5_four=number_swe_list5_four if UserCtry=="se"
replace number_nationals_list6_four=number_swe_list6_four if UserCtry=="se"
replace number_nationals_list7_four=number_swe_list7_four if UserCtry=="se"

* Number of co-nationals on each list (among three first candidates)

gen number_nationals_list1_three=number_fr_list1_three if UserCtry=="fr"
gen number_nationals_list2_three=number_fr_list2_three if UserCtry=="fr"
gen number_nationals_list3_three=number_fr_list3_three if UserCtry=="fr"
gen number_nationals_list4_three=number_fr_list4_three if UserCtry=="fr"
gen number_nationals_list5_three=number_fr_list5_three if UserCtry=="fr"
gen number_nationals_list6_three=number_fr_list6_three if UserCtry=="fr"
gen number_nationals_list7_three=number_fr_list7_three if UserCtry=="fr"

replace number_nationals_list1_three=number_ger_list1_three if UserCtry=="de"
replace number_nationals_list2_three=number_ger_list2_three if UserCtry=="de"
replace number_nationals_list3_three=number_ger_list3_three if UserCtry=="de"
replace number_nationals_list4_three=number_ger_list4_three if UserCtry=="de"
replace number_nationals_list5_three=number_ger_list5_three if UserCtry=="de"
replace number_nationals_list6_three=number_ger_list6_three if UserCtry=="de"
replace number_nationals_list7_three=number_ger_list7_three if UserCtry=="de"

replace number_nationals_list1_three=number_swe_list1_three if UserCtry=="se"
replace number_nationals_list2_three=number_swe_list2_three if UserCtry=="se"
replace number_nationals_list3_three=number_swe_list3_three if UserCtry=="se"
replace number_nationals_list4_three=number_swe_list4_three if UserCtry=="se"
replace number_nationals_list5_three=number_swe_list5_three if UserCtry=="se"
replace number_nationals_list6_three=number_swe_list6_three if UserCtry=="se"
replace number_nationals_list7_three=number_swe_list7_three if UserCtry=="se"

* Number of co-nationals on each list (among two first candidates)

gen number_nationals_list1_two=number_fr_list1_two if UserCtry=="fr"
gen number_nationals_list2_two=number_fr_list2_two if UserCtry=="fr"
gen number_nationals_list3_two=number_fr_list3_two if UserCtry=="fr"
gen number_nationals_list4_two=number_fr_list4_two if UserCtry=="fr"
gen number_nationals_list5_two=number_fr_list5_two if UserCtry=="fr"
gen number_nationals_list6_two=number_fr_list6_two if UserCtry=="fr"
gen number_nationals_list7_two=number_fr_list7_two if UserCtry=="fr"

replace number_nationals_list1_two=number_ger_list1_two if UserCtry=="de"
replace number_nationals_list2_two=number_ger_list2_two if UserCtry=="de"
replace number_nationals_list3_two=number_ger_list3_two if UserCtry=="de"
replace number_nationals_list4_two=number_ger_list4_two if UserCtry=="de"
replace number_nationals_list5_two=number_ger_list5_two if UserCtry=="de"
replace number_nationals_list6_two=number_ger_list6_two if UserCtry=="de"
replace number_nationals_list7_two=number_ger_list7_two if UserCtry=="de"

replace number_nationals_list1_two=number_swe_list1_two if UserCtry=="se"
replace number_nationals_list2_two=number_swe_list2_two if UserCtry=="se"
replace number_nationals_list3_two=number_swe_list3_two if UserCtry=="se"
replace number_nationals_list4_two=number_swe_list4_two if UserCtry=="se"
replace number_nationals_list5_two=number_swe_list5_two if UserCtry=="se"
replace number_nationals_list6_two=number_swe_list6_two if UserCtry=="se"
replace number_nationals_list7_two=number_swe_list7_two if UserCtry=="se"

* Number of co-nationals on each list (first candidate only)

gen number_nationals_list1_one=number_fr_list1_one if UserCtry=="fr"
gen number_nationals_list2_one=number_fr_list2_one if UserCtry=="fr"
gen number_nationals_list3_one=number_fr_list3_one if UserCtry=="fr"
gen number_nationals_list4_one=number_fr_list4_one if UserCtry=="fr"
gen number_nationals_list5_one=number_fr_list5_one if UserCtry=="fr"
gen number_nationals_list6_one=number_fr_list6_one if UserCtry=="fr"
gen number_nationals_list7_one=number_fr_list7_one if UserCtry=="fr"

replace number_nationals_list1_one=number_ger_list1_one if UserCtry=="de"
replace number_nationals_list2_one=number_ger_list2_one if UserCtry=="de"
replace number_nationals_list3_one=number_ger_list3_one if UserCtry=="de"
replace number_nationals_list4_one=number_ger_list4_one if UserCtry=="de"
replace number_nationals_list5_one=number_ger_list5_one if UserCtry=="de"
replace number_nationals_list6_one=number_ger_list6_one if UserCtry=="de"
replace number_nationals_list7_one=number_ger_list7_one if UserCtry=="de"

replace number_nationals_list1_one=number_swe_list1_one if UserCtry=="se"
replace number_nationals_list2_one=number_swe_list2_one if UserCtry=="se"
replace number_nationals_list3_one=number_swe_list3_one if UserCtry=="se"
replace number_nationals_list4_one=number_swe_list4_one if UserCtry=="se"
replace number_nationals_list5_one=number_swe_list5_one if UserCtry=="se"
replace number_nationals_list6_one=number_swe_list6_one if UserCtry=="se"
replace number_nationals_list7_one=number_swe_list7_one if UserCtry=="se"

* Co-national or not for each candidate of the list voted in under open-list

gen national_cand1=0
gen national_cand2=0
gen national_cand3=0
gen national_cand4=0
gen national_cand5=0
gen national_cand6=0
gen national_cand7=0
gen national_cand8=0
gen national_cand9=0
gen national_cand10=0

replace national_cand1=1 if UserCtry=="fr" & cty_cand1==10
replace national_cand2=1 if UserCtry=="fr" & cty_cand2==10
replace national_cand3=1 if UserCtry=="fr" & cty_cand3==10
replace national_cand4=1 if UserCtry=="fr" & cty_cand4==10
replace national_cand5=1 if UserCtry=="fr" & cty_cand5==10
replace national_cand6=1 if UserCtry=="fr" & cty_cand6==10
replace national_cand7=1 if UserCtry=="fr" & cty_cand7==10
replace national_cand8=1 if UserCtry=="fr" & cty_cand8==10
replace national_cand9=1 if UserCtry=="fr" & cty_cand9==10
replace national_cand10=1 if UserCtry=="fr" & cty_cand10==10

replace national_cand1=1 if UserCtry=="de" & cty_cand1==11
replace national_cand2=1 if UserCtry=="de" & cty_cand2==11
replace national_cand3=1 if UserCtry=="de" & cty_cand3==11
replace national_cand4=1 if UserCtry=="de" & cty_cand4==11
replace national_cand5=1 if UserCtry=="de" & cty_cand5==11
replace national_cand6=1 if UserCtry=="de" & cty_cand6==11
replace national_cand7=1 if UserCtry=="de" & cty_cand7==11
replace national_cand8=1 if UserCtry=="de" & cty_cand8==11
replace national_cand9=1 if UserCtry=="de" & cty_cand9==11
replace national_cand10=1 if UserCtry=="de" & cty_cand10==11

replace national_cand1=1 if UserCtry=="se" & cty_cand1==27
replace national_cand2=1 if UserCtry=="se" & cty_cand2==27
replace national_cand3=1 if UserCtry=="se" & cty_cand3==27
replace national_cand4=1 if UserCtry=="se" & cty_cand4==27
replace national_cand5=1 if UserCtry=="se" & cty_cand5==27
replace national_cand6=1 if UserCtry=="se" & cty_cand6==27
replace national_cand7=1 if UserCtry=="se" & cty_cand7==27
replace national_cand8=1 if UserCtry=="se" & cty_cand8==27
replace national_cand9=1 if UserCtry=="se" & cty_cand9==27
replace national_cand10=1 if UserCtry=="se" & cty_cand10==27

* Total number of points given

gen number_points=(mep1Rk+mep2Rk+mep3Rk+mep4Rk+mep5Rk+mep6Rk+mep7Rk+mep8Rk+mep9Rk+mep10Rk)/10

* Country dummies

gen france=0
replace france=1 if UserCtry=="fr"

gen germany=0
replace germany=1 if UserCtry=="de"

gen sweden=0
replace sweden=1 if UserCtry=="se"

* Party dummies

gen alde=0
replace alde=1 if euOpen==1
 

gen epp=0
replace epp=1 if euOpen==2

gen efd=0
replace efd=1 if euOpen==3

gen ecr=0
replace ecr=1 if euOpen==4

gen sd=0
replace sd=1 if euOpen==5

gen greens=0
replace greens=1 if euOpen==6

gen gue=0
replace gue=1 if euOpen==7

* Consistent pan-European vote

gen consistent_vote_c=.
replace consistent_vote_c=2 if natvote_closed==2 & UserCtry=="fr"
replace consistent_vote_c=5 if natvote_closed==3 & UserCtry=="fr"
replace consistent_vote_c=1 if natvote_closed==4 & UserCtry=="fr"
replace consistent_vote_c=6 if natvote_closed==5 & UserCtry=="fr"
replace consistent_vote_c=7 if natvote_closed==6 & UserCtry=="fr"
replace consistent_vote_c=. if natvote_closed==99 & UserCtry=="fr"
replace consistent_vote_c=. if natvote_closed==1 & UserCtry=="fr"

replace consistent_vote_c=2 if natvote_closed==1 & UserCtry=="de"
replace consistent_vote_c=5 if natvote_closed==2 & UserCtry=="de"
replace consistent_vote_c=6 if natvote_closed==3 & UserCtry=="de"
replace consistent_vote_c=7 if natvote_closed==4 & UserCtry=="de"
replace consistent_vote_c=. if natvote_closed==5 & UserCtry=="de"
replace consistent_vote_c=1 if natvote_closed==6 & UserCtry=="de"
replace consistent_vote_c=. if natvote_closed==8 & UserCtry=="de"
replace consistent_vote_c=. if natvote_closed==11 & UserCtry=="de"
replace consistent_vote_c=. if natvote_closed==99 & UserCtry=="de"
replace consistent_vote_c=. if natvote_closed==10 & UserCtry=="de"
replace consistent_vote_c=. if natvote_closed==13 & UserCtry=="de"
replace consistent_vote_c=. if natvote_closed==9 & UserCtry=="de"

replace consistent_vote_c=5 if natvote_closed==1 & UserCtry=="se"
replace consistent_vote_c=6 if natvote_closed==2 & UserCtry=="se"
replace consistent_vote_c=2 if natvote_closed==3 & UserCtry=="se"
replace consistent_vote_c=1 if natvote_closed==4 & UserCtry=="se"
replace consistent_vote_c=. if natvote_closed==5 & UserCtry=="se"
replace consistent_vote_c=1 if natvote_closed==6 & UserCtry=="se"
replace consistent_vote_c=7 if natvote_closed==7 & UserCtry=="se"
replace consistent_vote_c=2 if natvote_closed==8 & UserCtry=="se"
replace consistent_vote_c=. if natvote_closed==9 & UserCtry=="se"
replace consistent_vote_c=. if natvote_closed==99 & UserCtry=="se"

gen consistent_vote_o=.
replace consistent_vote_o=2 if natvote_open==2 & UserCtry=="fr"
replace consistent_vote_o=5 if natvote_open==3 & UserCtry=="fr"
replace consistent_vote_o=1 if natvote_open==4 & UserCtry=="fr"
replace consistent_vote_o=6 if natvote_open==5 & UserCtry=="fr"
replace consistent_vote_o=7 if natvote_open==6 & UserCtry=="fr"
replace consistent_vote_o=. if natvote_open==99 & UserCtry=="fr"
replace consistent_vote_o=. if natvote_open==1 & UserCtry=="fr"

replace consistent_vote_o=2 if natvote_open==1 & UserCtry=="de"
replace consistent_vote_o=5 if natvote_open==2 & UserCtry=="de"
replace consistent_vote_o=6 if natvote_open==3 & UserCtry=="de"
replace consistent_vote_o=7 if natvote_open==4 & UserCtry=="de"
replace consistent_vote_o=. if natvote_open==5 & UserCtry=="de"
replace consistent_vote_o=1 if natvote_open==6 & UserCtry=="de"
replace consistent_vote_o=. if natvote_open==8 & UserCtry=="de"
replace consistent_vote_o=. if natvote_open==11 & UserCtry=="de"
replace consistent_vote_o=. if natvote_open==99 & UserCtry=="de"
replace consistent_vote_o=. if natvote_open==10 & UserCtry=="de"
replace consistent_vote_o=. if natvote_open==9 & UserCtry=="de"

replace consistent_vote_o=5 if natvote_open==1 & UserCtry=="se"
replace consistent_vote_o=6 if natvote_open==2 & UserCtry=="se"
replace consistent_vote_o=2 if natvote_open==3 & UserCtry=="se"
replace consistent_vote_o=1 if natvote_open==4 & UserCtry=="se"
replace consistent_vote_o=. if natvote_open==5 & UserCtry=="se"
replace consistent_vote_o=1 if natvote_open==6 & UserCtry=="se"
replace consistent_vote_o=7 if natvote_open==7 & UserCtry=="se"
replace consistent_vote_o=2 if natvote_open==8 & UserCtry=="se"
replace consistent_vote_o=. if natvote_open==9 & UserCtry=="se"
replace consistent_vote_o=. if natvote_open==99 & UserCtry=="se"

* Saving data

// save [Your local path to a second version of the dataset "pan_european_district_data2.dta"], replace

* 2. Description of vote choice (aggregated)
*********************************************

* Creating a label

label define parties 1 "alde" 2 "epp" 3 "efd" 4 "ecr" 5 "sd" 6 "green" 7 "gue"
label values euClo parties
label values euOpen parties

* Table 1

tab euClo
tab euOpen

tab euClo [aweight=weight]
tab euOpen [aweight=weight]

* Table A1

bysort UserCtry: tab euClo
bysort UserCtry: tab euOpen

bysort UserCtry: tab euClo [aweight=weight]
bysort UserCtry: tab euOpen [aweight=weight]

* Proportion of subject liking pan-European district (in-text statistics)

tab q2

* 3. Analyses of preferential voting
*************************************

* Expanding dataset

expand 10
 
bysort id: gen cand = _n

gen cand_vote=.
replace cand_vote=mep1Rk if cand==1
replace cand_vote=mep2Rk if cand==2
replace cand_vote=mep3Rk if cand==3
replace cand_vote=mep4Rk if cand==4
replace cand_vote=mep5Rk if cand==5
replace cand_vote=mep6Rk if cand==6
replace cand_vote=mep7Rk if cand==7
replace cand_vote=mep8Rk if cand==8
replace cand_vote=mep9Rk if cand==9
replace cand_vote=mep10Rk if cand==10

gen national_cand=.
replace national_cand=national_cand1 if cand==1
replace national_cand=national_cand2 if cand==2
replace national_cand=national_cand3 if cand==3
replace national_cand=national_cand4 if cand==4
replace national_cand=national_cand5 if cand==5
replace national_cand=national_cand6 if cand==6
replace national_cand=national_cand7 if cand==7
replace national_cand=national_cand8 if cand==8
replace national_cand=national_cand9 if cand==9
replace national_cand=national_cand10 if cand==10

gen gender=.
replace gender=gender_cand1 if cand==1
replace gender=gender_cand2 if cand==2
replace gender=gender_cand3 if cand==3
replace gender=gender_cand4 if cand==4
replace gender=gender_cand5 if cand==5
replace gender=gender_cand6 if cand==6
replace gender=gender_cand7 if cand==7
replace gender=gender_cand8 if cand==8
replace gender=gender_cand9 if cand==9
replace gender=gender_cand10 if cand==10

gen birthy=.
replace birthy=birthy_cand1 if cand==1
replace birthy=birthy_cand2 if cand==2
replace birthy=birthy_cand3 if cand==3
replace birthy=birthy_cand4 if cand==4
replace birthy=birthy_cand5 if cand==5
replace birthy=birthy_cand6 if cand==6
replace birthy=birthy_cand7 if cand==7
replace birthy=birthy_cand8 if cand==8
replace birthy=birthy_cand9 if cand==9
replace birthy=birthy_cand10 if cand==10

gen age=2014-birthy

* Table 2

mlogit cand_vote national_cand age gender number_points alde epp ecr efd sd greens france germany [pweight=weight]

mlogit cand_vote national_cand age gender number_points alde epp ecr efd sd greens france germany [pweight=weight], rrr

* Figure A3

quietly mlogit cand_vote national_cand age gender number_points alde epp ecr efd sd greens [pweight=weight]
estimate store all

quietly mlogit cand_vote national_cand age gender number_points alde epp ecr efd sd greens [pweight=weight] if UserCtry=="fr"
estimate store france

quietly  mlogit cand_vote national_cand age gender number_points alde epp ecr efd sd greens [pweight=weight] if UserCtry=="de"
estimate store germany

quietly  mlogit cand_vote national_cand age gender number_points alde epp ecr efd sd greens [pweight=weight] if UserCtry=="se", rrr
estimate store sweden

coefplot all france germany sweden, keep(*:) drop(_cons age gender number_points alde epp ecr efd sd greens) xline(1) xlabel(0(3)21) eform

* 4. Analyses of list voting
*****************************

* Load second version of the dataset

// use [Your local path to the secodn version of the dataset 'pan_european_district_data2.dta"], clear

* Expanding dataset

expand 7
 
bysort id: gen list = _n
bysort id: gen vote_c = euClo == _n
bysort id: gen vote_o = euOpen == _n
bysort id: gen consistent_c = consistent_vote_c == _n
bysort id: gen consistent_o = consistent_vote_o == _n

gen number_nationals=.
replace number_nationals=number_nationals_list1 if list==1
replace number_nationals=number_nationals_list2 if list==2
replace number_nationals=number_nationals_list3 if list==3
replace number_nationals=number_nationals_list4 if list==4
replace number_nationals=number_nationals_list5 if list==5
replace number_nationals=number_nationals_list6 if list==6
replace number_nationals=number_nationals_list7 if list==7

gen number_women=.
replace number_women=number_women_list1 if list==1
replace number_women=number_women_list2 if list==2
replace number_women=number_women_list3 if list==3
replace number_women=number_women_list4 if list==4
replace number_women=number_women_list5 if list==5
replace number_women=number_women_list6 if list==6
replace number_women=number_women_list7 if list==7

gen age_list=.
replace age_list=age_list1 if list==1
replace age_list=age_list2 if list==2
replace age_list=age_list3 if list==3
replace age_list=age_list4 if list==4
replace age_list=age_list5 if list==5
replace age_list=age_list6 if list==6
replace age_list=age_list7 if list==7

* Creating variable presence or absence of co-national on the list

gen national_dummy=0
replace national_dummy=1 if number_nationals>0

* Table 3

clogit vote_c number_nationals consistent_c number_women age_list [pweight=weight], group(id)
clogit vote_c i.number_nationals consistent_c number_women age_list [pweight=weight], group(id)
clogit vote_c national_dummy consistent_c number_women age_list [pweight=weight], group(id)

clogit vote_c number_nationals consistent_c number_women age_list [pweight=weight], group(id) or 
clogit vote_c i.number_nationals consistent_c number_women age_list [pweight=weight], group(id) or
clogit vote_c national_dummy consistent_c number_women age_list [pweight=weight], group(id) or

* Table 4 

clogit vote_o number_nationals consistent_o number_women age_list [pweight=weight], group(id)
clogit vote_o i.number_nationals consistent_o number_women age_list [pweight=weight], group(id)
clogit vote_o national_dummy consistent_o number_women age_list [pweight=weight], group(id)

clogit vote_o number_nationals consistent_o number_women age_list [pweight=weight], group(id) or 
clogit vote_o i.number_nationals consistent_o number_women age_list [pweight=weight], group(id) or
clogit vote_o national_dummy consistent_o number_women age_list [pweight=weight], group(id) or

* Figure A4

quietly clogit vote_c national_dummy consistent_c number_women age_list [pweight=weight], group(id) or
estimate store A

quietly clogit vote_o national_dummy consistent_o number_women age_list [pweight=weight], group(id) or
estimate store B

quietly clogit vote_c national_dummy consistent_c number_women age_list [pweight=weight] if UserCtry=="fr", group(id) or
estimate store C

quietly clogit vote_o national_dummy consistent_o number_women age_list [pweight=weight] if UserCtry=="fr", group(id) or
estimate store D

quietly clogit vote_c national_dummy consistent_c number_women age_list [pweight=weight] if UserCtry=="de", group(id) or
estimate store E

quietly clogit vote_o national_dummy consistent_o number_women age_list [pweight=weight] if UserCtry=="de", group(id) or
estimate store F

quietly clogit vote_c national_dummy consistent_c number_women age_list [pweight=weight] if UserCtry=="se", group(id) or
estimate store G

quietly clogit vote_o national_dummy consistent_o number_women age_list [pweight=weight] if UserCtry=="se", group(id) or
estimate store H

coefplot A B C D E F G H, drop(_cons consistent_o consistent_c number_women age_list) xline(1) eform

* Figure A5

quietly clogit vote_c national_dummy consistent_c number_women age_list [pweight=weight], group(id) or
estimate store A

gen national_dummy_o=national_dummy
quietly clogit vote_o national_dummy_o consistent_o number_women age_list [pweight=weight], group(id) or
estimate store B

gen national_dummy_efd=national_dummy
quietly clogit vote_c national_dummy_efd consistent_c number_women age_list [pweight=weight] if list!=3, group(id) or
estimate store C

gen national_dummy_efd_o=national_dummy
quietly clogit vote_o national_dummy_efd_o consistent_o number_women age_list [pweight=weight] if list!=3, group(id) or
estimate store D

gen national_dummy_ecr=national_dummy
quietly clogit vote_c national_dummy_ecr consistent_c number_women age_list [pweight=weight] if list!=4, group(id) or
estimate store E

gen national_dummy_ecr_o=national_dummy
quietly clogit vote_o national_dummy_ecr_o consistent_o number_women age_list [pweight=weight] if list!=4, group(id) or
estimate store F

gen national_dummy_epp=national_dummy
quietly clogit vote_c national_dummy_epp consistent_c number_women age_list [pweight=weight] if list!=2, group(id) or
estimate store G

gen national_dummy_epp_o=national_dummy
quietly clogit vote_o national_dummy_epp_o consistent_o number_women age_list [pweight=weight] if list!=2, group(id) or
estimate store H

gen national_dummy_alde=national_dummy
quietly clogit vote_c national_dummy_alde consistent_c number_women age_list [pweight=weight] if list!=1, group(id) or
estimate store I

gen national_dummy_alde_o=national_dummy
quietly clogit vote_o national_dummy_alde_o consistent_o number_women age_list [pweight=weight] if list!=1, group(id) or
estimate store J

gen national_dummy_sd=national_dummy
quietly clogit vote_c national_dummy_sd consistent_c number_women age_list [pweight=weight] if list!=5, group(id) or
estimate store K

gen national_dummy_sd_o=national_dummy
quietly clogit vote_o national_dummy_sd_o consistent_o number_women age_list [pweight=weight] if list!=5, group(id) or
estimate store L

gen national_dummy_green=national_dummy
quietly clogit vote_c national_dummy_green consistent_c number_women age_list [pweight=weight] if list!=6, group(id) or
estimate store M

gen national_dummy_green_o=national_dummy
quietly clogit vote_o national_dummy_green_o consistent_o number_women age_list [pweight=weight] if list!=6, group(id) or
estimate store N

gen national_dummy_gue=national_dummy
quietly clogit vote_c national_dummy_gue consistent_c number_women age_list [pweight=weight] if list!=7, group(id) or
estimate store O

gen national_dummy_gue_o=national_dummy
quietly clogit vote_o national_dummy_gue_o  consistent_o number_women age_list [pweight=weight] if list!=7, group(id) or
estimate store P

coefplot A B C D E F G H I J K L M N O P, drop(_cont consistent_c consistent_o number_women age_list) xline(1) eform
 
* Figure A6

gen number_nationals_nine=.
replace number_nationals_nine=number_nationals_list1_nine if list==1
replace number_nationals_nine=number_nationals_list2_nine if list==2
replace number_nationals_nine=number_nationals_list3_nine if list==3
replace number_nationals_nine=number_nationals_list4_nine if list==4
replace number_nationals_nine=number_nationals_list5_nine if list==5
replace number_nationals_nine=number_nationals_list6_nine if list==6
replace number_nationals_nine=number_nationals_list7_nine if list==7

gen number_nationals_eight=.
replace number_nationals_eight=number_nationals_list1_eight if list==1
replace number_nationals_eight=number_nationals_list2_eight if list==2
replace number_nationals_eight=number_nationals_list3_eight if list==3
replace number_nationals_eight=number_nationals_list4_eight if list==4
replace number_nationals_eight=number_nationals_list5_eight if list==5
replace number_nationals_eight=number_nationals_list6_eight if list==6
replace number_nationals_eight=number_nationals_list7_eight if list==7

gen number_nationals_seven=.
replace number_nationals_seven=number_nationals_list1_seven if list==1
replace number_nationals_seven=number_nationals_list2_seven if list==2
replace number_nationals_seven=number_nationals_list3_seven if list==3
replace number_nationals_seven=number_nationals_list4_seven if list==4
replace number_nationals_seven=number_nationals_list5_seven if list==5
replace number_nationals_seven=number_nationals_list6_seven if list==6
replace number_nationals_seven=number_nationals_list7_seven if list==7

gen number_nationals_six=.
replace number_nationals_six=number_nationals_list1_six if list==1
replace number_nationals_six=number_nationals_list2_six if list==2
replace number_nationals_six=number_nationals_list3_six if list==3
replace number_nationals_six=number_nationals_list4_six if list==4
replace number_nationals_six=number_nationals_list5_six if list==5
replace number_nationals_six=number_nationals_list6_six if list==6
replace number_nationals_six=number_nationals_list7_six if list==7

gen number_nationals_five=.
replace number_nationals_five=number_nationals_list1_five if list==1
replace number_nationals_five=number_nationals_list2_five if list==2
replace number_nationals_five=number_nationals_list3_five if list==3
replace number_nationals_five=number_nationals_list4_five if list==4
replace number_nationals_five=number_nationals_list5_five if list==5
replace number_nationals_five=number_nationals_list6_five if list==6
replace number_nationals_five=number_nationals_list7_five if list==7

gen number_nationals_four=.
replace number_nationals_four=number_nationals_list1_four if list==1
replace number_nationals_four=number_nationals_list2_four if list==2
replace number_nationals_four=number_nationals_list3_four if list==3
replace number_nationals_four=number_nationals_list4_four if list==4
replace number_nationals_four=number_nationals_list5_four if list==5
replace number_nationals_four=number_nationals_list6_four if list==6
replace number_nationals_four=number_nationals_list7_four if list==7

gen number_nationals_three=.
replace number_nationals_three=number_nationals_list1_three if list==1
replace number_nationals_three=number_nationals_list2_three if list==2
replace number_nationals_three=number_nationals_list3_three if list==3
replace number_nationals_three=number_nationals_list4_three if list==4
replace number_nationals_three=number_nationals_list5_three if list==5
replace number_nationals_three=number_nationals_list6_three if list==6
replace number_nationals_three=number_nationals_list7_three if list==7

gen number_nationals_two=.
replace number_nationals_two=number_nationals_list1_two if list==1
replace number_nationals_two=number_nationals_list2_two if list==2
replace number_nationals_two=number_nationals_list3_two if list==3
replace number_nationals_two=number_nationals_list4_two if list==4
replace number_nationals_two=number_nationals_list5_two if list==5
replace number_nationals_two=number_nationals_list6_two if list==6
replace number_nationals_two=number_nationals_list7_two if list==7

gen number_nationals_one=.
replace number_nationals_one=number_nationals_list1_one if list==1
replace number_nationals_one=number_nationals_list2_one if list==2
replace number_nationals_one=number_nationals_list3_one if list==3
replace number_nationals_one=number_nationals_list4_one if list==4
replace number_nationals_one=number_nationals_list5_one if list==5
replace number_nationals_one=number_nationals_list6_one if list==6
replace number_nationals_one=number_nationals_list7_one if list==7

replace number_nationals_nine=1 if number_nationals_nine>0
replace number_nationals_eight=1 if number_nationals_eight>0
replace number_nationals_seven=1 if number_nationals_seven>0
replace number_nationals_six=1 if number_nationals_six>0
replace number_nationals_five=1 if number_nationals_five>0
replace number_nationals_four=1 if number_nationals_four>0
replace number_nationals_three=1 if number_nationals_three>0
replace number_nationals_two=1 if number_nationals_two>0
replace number_nationals_one=1 if number_nationals_one>0

quietly clogit vote_c national_dummy consistent_c number_women age_list [pweight=weight], group(id) or
estimate store A

gen national_dummy_o=national_dummy
quietly clogit vote_o national_dummy_o consistent_o number_women age_list [pweight=weight], group(id) or
estimate store B

quietly clogit vote_c number_nationals_nine consistent_c number_women age_list [pweight=weight], group(id) or
estimate store C

gen number_nationals_nine_o=number_nationals_nine
quietly clogit vote_o number_nationals_nine_o consistent_o number_women age_list [pweight=weight], group(id) or
estimate store D

quietly clogit vote_c number_nationals_eight consistent_c number_women age_list [pweight=weight], group(id) or
estimate store E

gen number_nationals_eight_o=number_nationals_eight
quietly clogit vote_o number_nationals_eight_o consistent_o number_women age_list [pweight=weight], group(id) or
estimate store F

quietly clogit vote_c number_nationals_seven consistent_c number_women age_list [pweight=weight], group(id) or
estimate store G

gen number_nationals_seven_o=number_nationals_seven
quietly clogit vote_o number_nationals_seven_o consistent_o number_women age_list [pweight=weight], group(id) or
estimate store H

quietly clogit vote_c number_nationals_six consistent_c number_women age_list [pweight=weight], group(id) or
estimate store I

gen number_nationals_six_o=number_nationals_six
quietly clogit vote_o number_nationals_six_o consistent_o number_women age_list [pweight=weight], group(id) or
estimate store J

quietly clogit vote_c number_nationals_five consistent_c number_women age_list [pweight=weight], group(id) or
estimate store K

gen number_nationals_five_o=number_nationals_five
quietly clogit vote_o number_nationals_five_o consistent_o number_women age_list [pweight=weight], group(id) or
estimate store L

quietly clogit vote_c number_nationals_four consistent_c number_women age_list [pweight=weight], group(id) or
estimate store M

gen number_nationals_four_o=number_nationals_four
quietly clogit vote_o number_nationals_four_o consistent_o number_women age_list [pweight=weight], group(id) or
estimate store N

quietly clogit vote_c number_nationals_three consistent_c number_women age_list [pweight=weight], group(id) or
estimate store O

gen number_nationals_three_o=number_nationals_three
quietly clogit vote_o number_nationals_three_o consistent_o number_women age_list [pweight=weight], group(id) or
estimate store P

quietly clogit vote_c number_nationals_two consistent_c number_women age_list [pweight=weight], group(id) or
estimate store Q

gen number_nationals_two_o=number_nationals_two
quietly clogit vote_o number_nationals_two_o consistent_o number_women age_list [pweight=weight], group(id) or
estimate store R

quietly clogit vote_c number_nationals_one consistent_c number_women age_list [pweight=weight], group(id) or
estimate store S

gen number_nationals_one_o=number_nationals_one
quietly clogit vote_o number_nationals_one_o consistent_o number_women age_list [pweight=weight], group(id) or
estimate store T

coefplot A B C D E F G H I J K L M N O P Q R S T, drop(_cons consistent_c consistent_o number_women age_list) xline(1) eform


* Table 5

quietly clogit vote_c national_dummy consistent_c number_women age_list [pweight=weight], group(id)
predict predprob_c
quietly clogit vote_o national_dummy consistent_o number_women age_list [pweight=weight], group(id)
predict predprob_o

gen national_dummy2=national_dummy
quietly clogit vote_c national_dummy2 consistent_c number_women age_list [pweight=weight], group(id)
replace national_dummy2=1
predict predprob_c2

gen national_dummy3=national_dummy
quietly clogit vote_o national_dummy3 consistent_o number_women age_list [pweight=weight], group(id)
replace national_dummy3=1
predict predprob_o2

bysort id: egen max_predprob_c=max(predprob_c)
bysort id: egen max_predprob_c2=max(predprob_c2)
bysort id: egen max_predprob_o=max(predprob_o)
bysort id: egen max_predprob_o2=max(predprob_o2)

gen predvote_c=0
gen predvote_c2=0
gen predvote_o=0
gen predvote_o2=0

replace predvote_c=1 if predprob_c==max_predprob_c
replace predvote_c2=1 if predprob_c2==max_predprob_c2
replace predvote_o=1 if predprob_o==max_predprob_o
replace predvote_o2=1 if predprob_o2==max_predprob_o2

bysort id: egen sum_predvote_c=total(predvote_c)
bysort id: egen sum_predvote_c2=total(predvote_c2)
bysort id: egen sum_predvote_o=total(predvote_o)
bysort id: egen sum_predvote_o2=total(predvote_o2)

replace predvote_c=vote_c if sum_predvote_c>1
replace predvote_c2=vote_c if sum_predvote_c2>1
replace predvote_o=vote_o if sum_predvote_o>1
replace predvote_o2=vote_o if sum_predvote_o2>1

gen predvote_c_party1=0
gen predvote_c_party2=0
gen predvote_c_party3=0
gen predvote_c_party4=0
gen predvote_c_party5=0
gen predvote_c_party6=0
gen predvote_c_party7=0

gen predvote_c2_party1=0
gen predvote_c2_party2=0
gen predvote_c2_party3=0
gen predvote_c2_party4=0
gen predvote_c2_party5=0
gen predvote_c2_party6=0
gen predvote_c2_party7=0

gen predvote_o_party1=0
gen predvote_o_party2=0
gen predvote_o_party3=0
gen predvote_o_party4=0
gen predvote_o_party5=0
gen predvote_o_party6=0
gen predvote_o_party7=0

gen predvote_o2_party1=0
gen predvote_o2_party2=0
gen predvote_o2_party3=0
gen predvote_o2_party4=0
gen predvote_o2_party5=0
gen predvote_o2_party6=0
gen predvote_o2_party7=0

replace predvote_c_party1=1 if predvote_c==1 & list==1
replace predvote_c_party2=1 if predvote_c==1 & list==2
replace predvote_c_party3=1 if predvote_c==1 & list==3
replace predvote_c_party4=1 if predvote_c==1 & list==4
replace predvote_c_party5=1 if predvote_c==1 & list==5
replace predvote_c_party6=1 if predvote_c==1 & list==6
replace predvote_c_party7=1 if predvote_c==1 & list==7

replace predvote_c2_party1=1 if predvote_c2==1 & list==1
replace predvote_c2_party2=1 if predvote_c2==1 & list==2
replace predvote_c2_party3=1 if predvote_c2==1 & list==3
replace predvote_c2_party4=1 if predvote_c2==1 & list==4
replace predvote_c2_party5=1 if predvote_c2==1 & list==5
replace predvote_c2_party6=1 if predvote_c2==1 & list==6
replace predvote_c2_party7=1 if predvote_c2==1 & list==7

replace predvote_o_party1=1 if predvote_o==1 & list==1
replace predvote_o_party2=1 if predvote_o==1 & list==2
replace predvote_o_party3=1 if predvote_o==1 & list==3
replace predvote_o_party4=1 if predvote_o==1 & list==4
replace predvote_o_party5=1 if predvote_o==1 & list==5
replace predvote_o_party6=1 if predvote_o==1 & list==6
replace predvote_o_party7=1 if predvote_o==1 & list==7

replace predvote_o2_party1=1 if predvote_o2==1 & list==1
replace predvote_o2_party2=1 if predvote_o2==1 & list==2
replace predvote_o2_party3=1 if predvote_o2==1 & list==3
replace predvote_o2_party4=1 if predvote_o2==1 & list==4
replace predvote_o2_party5=1 if predvote_o2==1 & list==5
replace predvote_o2_party6=1 if predvote_o2==1 & list==6
replace predvote_o2_party7=1 if predvote_o2==1 & list==7

bysort id: egen predvote_c_party1_tot=total(predvote_c_party1)
bysort id: egen predvote_c_party2_tot=total(predvote_c_party2)
bysort id: egen predvote_c_party3_tot=total(predvote_c_party3)
bysort id: egen predvote_c_party4_tot=total(predvote_c_party4)
bysort id: egen predvote_c_party5_tot=total(predvote_c_party5)
bysort id: egen predvote_c_party6_tot=total(predvote_c_party6)
bysort id: egen predvote_c_party7_tot=total(predvote_c_party7)

bysort id: egen predvote_c2_party1_tot=total(predvote_c2_party1)
bysort id: egen predvote_c2_party2_tot=total(predvote_c2_party2)
bysort id: egen predvote_c2_party3_tot=total(predvote_c2_party3)
bysort id: egen predvote_c2_party4_tot=total(predvote_c2_party4)
bysort id: egen predvote_c2_party5_tot=total(predvote_c2_party5)
bysort id: egen predvote_c2_party6_tot=total(predvote_c2_party6)
bysort id: egen predvote_c2_party7_tot=total(predvote_c2_party7)

bysort id: egen predvote_o_party1_tot=total(predvote_o_party1)
bysort id: egen predvote_o_party2_tot=total(predvote_o_party2)
bysort id: egen predvote_o_party3_tot=total(predvote_o_party3)
bysort id: egen predvote_o_party4_tot=total(predvote_o_party4)
bysort id: egen predvote_o_party5_tot=total(predvote_o_party5)
bysort id: egen predvote_o_party6_tot=total(predvote_o_party6)
bysort id: egen predvote_o_party7_tot=total(predvote_o_party7)

bysort id: egen predvote_o2_party1_tot=total(predvote_o2_party1)
bysort id: egen predvote_o2_party2_tot=total(predvote_o2_party2)
bysort id: egen predvote_o2_party3_tot=total(predvote_o2_party3)
bysort id: egen predvote_o2_party4_tot=total(predvote_o2_party4)
bysort id: egen predvote_o2_party5_tot=total(predvote_o2_party5)
bysort id: egen predvote_o2_party6_tot=total(predvote_o2_party6)
bysort id: egen predvote_o2_party7_tot=total(predvote_o2_party7)

gen predvote_c_cat=0
replace predvote_c_cat=1 if predvote_c_party1_tot==1
replace predvote_c_cat=2 if predvote_c_party2_tot==1
replace predvote_c_cat=3 if predvote_c_party3_tot==1
replace predvote_c_cat=4 if predvote_c_party4_tot==1
replace predvote_c_cat=5 if predvote_c_party5_tot==1
replace predvote_c_cat=6 if predvote_c_party6_tot==1
replace predvote_c_cat=7 if predvote_c_party7_tot==1

gen predvote_c2_cat=0
replace predvote_c2_cat=1 if predvote_c2_party1_tot==1
replace predvote_c2_cat=2 if predvote_c2_party2_tot==1
replace predvote_c2_cat=3 if predvote_c2_party3_tot==1
replace predvote_c2_cat=4 if predvote_c2_party4_tot==1
replace predvote_c2_cat=5 if predvote_c2_party5_tot==1
replace predvote_c2_cat=6 if predvote_c2_party6_tot==1
replace predvote_c2_cat=7 if predvote_c2_party7_tot==1

gen predvote_o_cat=0
replace predvote_o_cat=1 if predvote_o_party1_tot==1
replace predvote_o_cat=2 if predvote_o_party2_tot==1
replace predvote_o_cat=3 if predvote_o_party3_tot==1
replace predvote_o_cat=4 if predvote_o_party4_tot==1
replace predvote_o_cat=5 if predvote_o_party5_tot==1
replace predvote_o_cat=6 if predvote_o_party6_tot==1
replace predvote_o_cat=7 if predvote_o_party7_tot==1

gen predvote_o2_cat=0
replace predvote_o2_cat=1 if predvote_o2_party1_tot==1
replace predvote_o2_cat=2 if predvote_o2_party2_tot==1
replace predvote_o2_cat=3 if predvote_o2_party3_tot==1
replace predvote_o2_cat=4 if predvote_o2_party4_tot==1
replace predvote_o2_cat=5 if predvote_o2_party5_tot==1
replace predvote_o2_cat=6 if predvote_o2_party6_tot==1
replace predvote_o2_cat=7 if predvote_o2_party7_tot==1

gen const_c=0
replace const_c=1 if predvote_c2_cat==predvote_c_cat
tab const_c [aw=weight] if list==1

gen const_o=0
replace const_o=1 if predvote_o2_cat==predvote_o_cat
tab const_o [aw=weight] if list==1

label value predvote_c_cat parties
label value predvote_o_cat parties
label value predvote_c2_cat parties
label value predvote_o2_cat parties

tab predvote_c2_cat [aweight=weight]
tab predvote_c2_cat predvote_c_cat [aw=weight] if list==1, ro

tab predvote_o2_cat [aweight=weight]
tab predvote_o2_cat predvote_o_cat [aw=weight] if list==1, ro

